home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AEWIN100.ARJ / BASEWIN.H < prev    next >
C/C++ Source or Header  |  1991-10-28  |  10KB  |  311 lines

  1. /**********************************************************************
  2.  *  
  3.  *  NAME:           basewin.h
  4.  *  
  5.  *  DESCRIPTION:    
  6.  *  
  7.  *  copyright (c) 1990 J. Alan Eldridge
  8.  * 
  9.  *  M O D I F I C A T I O N   H I S T O R Y
  10.  *
  11.  *  when        who                 what
  12.  *  -------------------------------------------------------------------
  13.  *  11/29/90    JAE                 created
  14.  *  
  15.  *********************************************************************/
  16.  
  17. #ifndef __BASEWIN_H
  18. #define __BASEWIN_H
  19.  
  20. //  define EXTENDED_IO_MANIPS to 1 if you want the extra
  21. //  i/o manipulators "<< setpos(y,x)" and "<< setattr(a)".
  22.  
  23. #define EXTENDED_IO_MANIPS  1
  24.  
  25. class basewin: 
  26.     public vidbuf,
  27.     public viewport {
  28.  
  29. private:
  30.  
  31.     uchar   fWrap:      1,  //  line wrap flag
  32.             fScroll:    1,  //  scroll port flag
  33.             fFrame:     1,  //  has a frame
  34.             fCloseBox:  1;  //  has a close box
  35.             
  36.     void    zflags()        //  zap the flags
  37.         { fWrap = fScroll = fFrame = fCloseBox = FALSE; }
  38.  
  39.     uchar   att;            //  video attribute
  40.     int     ydirty[2],      //  first,last dirty row
  41.             (*xdirty)[2];   //  first,last dirty col on each row
  42.                             //  note: decl. is "ptr to array of 2 uchars"
  43.  
  44. protected:
  45.  
  46.     //  dirty region handling
  47.     void    mark(int row);
  48.     void    markline(int row, int col);
  49.     void    unmark();
  50.     void    touch(int yul, int xul, int ylr, int xlr);
  51.  
  52.     //  scroll a region of the window
  53.     void    scroll(int yul, int xul, int ylr, int xlr, int nLines = 1);
  54.  
  55.     //  draw a box in the window
  56.     void    box(int yul, int xul, int ylr, int xlr, int vchr, int hchr,
  57.         int fillflg = 0, int fillchr = ' ');
  58.  
  59. public:    
  60.  
  61.     //  constructor
  62.     basewin(int yul, int xul, int ylr, int xlr);
  63.  
  64.     //  destructor
  65.     ~basewin();
  66.  
  67.     //  video attribute control
  68.     //  these are virtual because a Window has more intelligent
  69.     //  mechanisms for handling screen colors
  70.     virtual void    setattr(uchar a)
  71.         { att = a; }
  72.     virtual int     getattr()
  73.         { return att; }
  74.     int iscolor()   //  for convenience
  75.         { return vid_ISCOLOR; }
  76.         
  77.     //  touch all of port or window
  78.     void    touch()         //  just the current port
  79.         { touch(yUL, xUL, yLR, xLR); }
  80.     void    touchall()      //  the whole window
  81.         { touch(0, 0, rows-1, cols-1); }
  82.  
  83.     //  scroll current port
  84.     void    scroll(int nLines = 1) 
  85.         { scroll(yUL, xUL, yLR, xLR, nLines); }
  86.         
  87.     //  set/get cursor (relative to port)
  88.     virtual void    setpos(int y, int x)
  89.         { yCur = y+yUL; xCur = x+xUL; }
  90.     virtual void    getpos(int &y, int &x)
  91.         { y = yCur-yUL; x = xCur-xUL; }
  92.  
  93.     //  change viewport & home cursor
  94.     virtual void    setport(int yul, int xul, int ylr, int xlr)
  95.         { viewport::setport(yul,xul,ylr,xlr); setpos(0,0); }
  96.     virtual void    setport(int *box)
  97.         { basewin::setport(box[0],box[1],box[2],box[3]); }
  98.     virtual void    setport(viewport &vp)
  99.         { viewport::setport(vp); setpos(0,0); }
  100.     void  fullport()
  101.         { setport(0,0,rows-1,cols-1); }
  102.                 
  103.     //  character output
  104.     //  all of these return refs to the window so they can be
  105.     //  chained together, e.g., w.put("hello").NL().put("world").refresh()
  106.     //  (syntactically, it's a little ugly, but ...)    
  107.     basewin &NL();      //  newline
  108.     basewin &CR();      //  carriage return
  109.     basewin &BS();      //  backspace
  110.      
  111.     basewin &put(uchar c);              //  write a character
  112.     basewin &put(uchar *s);             //  write a string
  113.     basewin ¢er(int line, uchar *s);    //  center a string
  114.     basewin ¢er(uchar *s)           //  center a string
  115.         { return center(yCur, s); }
  116.     basewin &printf(uchar *fmt, ...);   //  printf() to window
  117.     basewin &operator<<(uchar c)        //  alternate character output
  118.         { return put(c); }
  119.     basewin &operator<<(uchar *s)       //  alternate string output
  120.         { return put(s); }
  121.  
  122.     //  clear part/all of the current port
  123.     basewin &clear(uchar ch = ' ');  //  the whole port
  124.     basewin &clreol(uchar ch = ' '); //  clear to end of line
  125.  
  126.     //  "i/o manipulator" helper
  127.     basewin &operator<<(basewin &(*f)(basewin &))
  128.         { return f(*this); }
  129.  
  130.     //  draw a box 
  131.     enum {
  132.         boxLine1 = UCHAR_MAX + 1,
  133.         boxLine2
  134.     };
  135.     void    box(int vchr, int hchr, int fillflg = FALSE, int fillchr = ' ')
  136.         { box(yUL, xUL, yLR, xLR, vchr, hchr, fillflg, fillchr); }
  137.     void    frame(int vchr, int hchr, int fillflg = FALSE, int fillchr = ' ');
  138.     void    closebox();
  139.         
  140.     //  read character/attrib at current position
  141.     int     get()
  142.         { return vidptr(yCur, xCur)->get(); }
  143.     int     geta()
  144.         { return vidptr(yCur, xCur)->geta(); }
  145.         
  146.     //  get a string from the user
  147.     
  148.     enum {
  149.         trimStr     =   0x01,               //  trim trailing blanks
  150.         expandStr   =   0x02,               //  keep padded to max length
  151.         autoTab     =   0x04|0x02,          //  cursor left/right out of field
  152.         zapField    =   0x08,               //  first key is print ==> erase field
  153.         noErrBeep   =   0x10                //  no beep if can't process key
  154.     };
  155.     
  156.     int editfld(
  157.             uchar   *pBuf,
  158.             int     bMax,
  159.             int     *pTermKeys = 0,
  160.             int     eFlags = trimStr,
  161.             int     (*OKFunc)(int c) = 0,
  162.             int     fillChr = ' ');
  163.  
  164.     int egetstr(uchar *pBuf);
  165.     int getstr(uchar *pBuf);
  166.     int operator>>(uchar *pBuf)
  167.         { return getstr(pBuf); }
  168.         
  169.     //  update to display screen
  170.     virtual void    refresh(int vflag=1);   //  refresh dirty area only
  171.  
  172.     //  manipulate flags
  173.     int     wrapok()                    //  get line wrap state
  174.         { return fWrap; }
  175.     void    wrapok(int flag)            //  turn line wrap on/off
  176.         { fWrap = flag != 0; }
  177.     int     scrollok()                  //  get scrolling state
  178.         { return fScroll; }
  179.     void    scrollok(int flag)          //  turn scrolling on/off
  180.         { fScroll = flag != 0; }
  181.     
  182.     //  read keyboard
  183.     int     keyrdy()                    //  is a key ready?
  184.         {   return kbd_ready(); }
  185.     int     getkey()                    //  wait for & return key
  186.         { return kbd_getkey(); }
  187.     void    operator>>(int &c)          //  wait for & return key
  188.         { c = getkey(); }
  189. };
  190.  
  191. //  these are like parameterless i/o manipulators
  192. //  e.g., w << "Hello, world" << nl << refresh;
  193.     
  194. inline basewin  &nl(basewin &w)
  195.     {   return w.NL(); }
  196. inline basewin  &cr(basewin &w)
  197.     {   return w.CR(); }
  198. inline basewin  &bs(basewin &w)
  199.     {   return w.BS(); }
  200. inline basewin  &refresh(basewin &w)
  201.     {   w.refresh(); return w; }
  202. inline basewin  &clear(basewin &w)
  203.     {   return w.clear(); }
  204. inline basewin  &clreol(basewin &w)
  205.     {   return w.clreol(); }
  206.  
  207. #if EXTENDED_IO_MANIPS
  208.  
  209. //  this class allows w << setpos(y,x)
  210.  
  211. class basewin_cpos {
  212. private:
  213.     int y, x;
  214.     basewin &setcursor(basewin &w)
  215.         { w.setpos(y,x); return w; }
  216. protected:
  217.     basewin_cpos(int r, int c): y(r), x(c) { }
  218. public:
  219.     friend basewin_cpos setpos(int r, int c)
  220.         { return basewin_cpos(r,c); }
  221.     friend basewin &
  222.     operator<<(basewin &w, basewin_cpos cp)
  223.         { return cp.setcursor(w); }
  224. };            
  225.  
  226. //  this class allows w << setattr(a)
  227.  
  228. class basewin_attr {
  229. private:
  230.     uchar   a;
  231.     basewin &setattr(basewin &w)
  232.         { w.setattr(a); return w; }
  233. protected:
  234.     basewin_attr(int att): a(att) { }
  235. public:
  236.     friend basewin_attr setattr(int a)
  237.         { return basewin_attr(a); }
  238.     friend basewin &
  239.     operator<<(basewin &w, basewin_attr a)
  240.         { return a.setattr(w); }
  241. };            
  242.  
  243. #endif
  244.  
  245. //  lookup tables for ibm line drawing characters
  246.  
  247. extern  uchar   UWLineChars     [][2];
  248. extern  uchar   UWTeeChars      [][2][2];
  249. extern  uchar   UWCornerChars   [][2][2];
  250.  
  251. //  values for args to teechar(), cornerchar(), and linechar()
  252.  
  253. #define SINGLE_LINE     0
  254. #define DOUBLE_LINE     1
  255.  
  256. #define LINE_HORZ       0
  257. #define LINE_VERT       1
  258.  
  259. #define TEE_TOP         0
  260. #define TEE_RIGHT       1
  261. #define TEE_BOTTOM      2
  262. #define TEE_LEFT        3
  263. #define TEE_CENTER      4
  264.  
  265. #define CORNER_UL       0
  266. #define CORNER_UR       1
  267. #define CORNER_LR       2
  268. #define CORNER_LL       3
  269.  
  270. //  these inline functions access the line drawing char arrays
  271.  
  272. inline int  linechar(int vertp, int dblp)
  273.     { return UWLineChars[vertp][dblp]; }
  274. inline int  teechar(int pos, int v, int h)
  275.     { return UWTeeChars[pos][v][h]; }
  276. inline int  cornerchar(int pos, int v, int h)
  277.     { return UWCornerChars[pos][v][h]; }
  278.  
  279. //  defines for gray box characters (incl. alternate spelling)
  280.  
  281. #define GRAYBOX0    176
  282. #define GREYBOX0    176
  283. #define GRAYBOX1    177
  284. #define GREYBOX1    177
  285. #define GRAYBOX2    178
  286. #define GREYBOX2    178
  287. #define BLACKBOX    219
  288.  
  289. //  defines for partial box characters
  290.  
  291. #define BOX_ENTIRE  BLACKBOX
  292. #define BOX_LOWER   220
  293. #define BOX_LEFT    221
  294. #define BOX_RIGHT   222
  295. #define BOX_UPPER   223
  296.  
  297. //  initialize the window library
  298.  
  299. int initscr(
  300.     int     vidmode = LASTMODE,
  301.     char    *vidvar = 0);
  302.  
  303. //  function to annoy the user
  304.  
  305. void beep(
  306.     int     nTimes = 1,
  307.     uint    howLong = 333,
  308.     uint    Hz = 880);
  309.  
  310. #endif
  311.